package com.android.lazysearch;
import java.util.ArrayList;

import com.android.lazysearch.LazySearch.ImageAdapter;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.Gallery;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;

public class MenuItemsActivity extends Activity{

	private Context mContext;
	private MenuItemsAdapter iAdapter;
	private ArrayList<Item> items;
	private String restaurantName;
	private Item addedItem;
	private Gallery g;
	
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.thumbnails);
		mContext = this;
//		setContentView(R.layout.thumbnail_screen);
//		FrameLayout stub = (FrameLayout)findViewById(R.id.stub_frame);	
//		LayoutInflater layoutInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//		layoutInflater.inflate(R.layout.thumbnails,stub);
		
		Bundle bundle = this.getIntent().getExtras();
		restaurantName = bundle.getString("restaurantName");
		items = bundle.getParcelableArrayList("items"); 		
        iAdapter = new MenuItemsAdapter(mContext, items);
        
        TextView tv = (TextView) findViewById(R.id.restaurantName);
        tv.setText(restaurantName);
        GridView gridView = (GridView) findViewById(R.id.grid_tables);
        gridView.setAdapter(iAdapter);
        gridView.setOnItemClickListener(itemClickListener);
        
//        g = (Gallery) findViewById(R.id.menu_gallery);        
//        g.setAdapter(new ImageAdapter(this));
//
//        g.setOnItemSelectedListener(new OnItemSelectedListener() {
//        	public void onClick(View v) {
//				
//	        }
//
//			@Override
//			public void onItemSelected(AdapterView<?> arg0, View arg1,
//					int arg2, long arg3) {
//				
//				ViewHolder v = (ViewHolder) arg1.getTag();
//				addedItem = v.holderItem;
//				//Toast.makeText(LazySearch.this, "" + addedItem.getItemName()+" "+addedItem.getDesc()+" "+addedItem.getItemPrice(), Toast.LENGTH_SHORT).show();
//			}
//
//			@Override
//			public void onNothingSelected(AdapterView<?> arg0) {
//				// TODO Auto-generated method stub
//				
//			}
//	    });    
	}
	
	//get the selected item to be displayed in the items gallery
    private OnItemClickListener itemClickListener = new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//        	Intent intent = new Intent(mContext,LazySearch.class);
//    		Bundle bundle = new Bundle();
//    		Item selectedItem = (Item) iAdapter.getItem(position);
//    		bundle.putParcelable("selectedItem", selectedItem);
//    		bundle.putInt("itemPosition", position);
//    		intent.putExtras(bundle);
//    		setResult(RESULT_OK, intent);
//    	    finish();
//    		mContext.startActivity(intent);
        }
    };
    
//	public class ImageAdapter extends BaseAdapter 
//    {
//		private Activity activity;
//		private LayoutInflater inflater = null;
//				
//        public ImageAdapter(Activity a) {
//            activity = a;
//            inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//        }
//        
//        public int getCount() {
//            return items.size();
//        }
//
//        public Object getItem(int position) {
//            return position;
//        }
//
//        public long getItemId(int position) {
//            return position;
//        }
//
//        public class ViewHolder {
//            public TextView price;
//            public TextView desc;
//            public ImageView itemImage;
//            public ImageView itemRating;
//            public Item holderItem;
//        }
//        
//        public View getView(int position, View convertView, ViewGroup parent) {
//            View vi = convertView;
//            ViewHolder holder;
//            if(convertView == null)
//            {
//                vi = inflater.inflate(R.layout.gallery, null);
//                holder = new ViewHolder();
//                holder.price = (TextView)vi.findViewById(R.id.textView1);
//                holder.desc = (TextView)vi.findViewById(R.id.textView2);
//                holder.itemImage = (ImageView)vi.findViewById(R.id.image1);
//                holder.itemRating = (ImageView)vi.findViewById(R.id.image2);
//                vi.setTag(holder);
//            }
//            else
//            {
//                holder = (ViewHolder)vi.getTag();
//            }
//            holder.desc.setText(items.get(position).getDesc());
//            holder.itemImage.setImageResource(items.get(position).getItemImage());
//            holder.itemRating.setImageResource(items.get(position).getItemRating());
//            holder.price.setText("$"+items.get(position).getItemPrice());
//            holder.holderItem = items.get(position);
//            //Toast.makeText(LazySearch.this, "" + holder.desc.getText(), Toast.LENGTH_SHORT).show();
//            return vi;      	
//        }
//    }
}
